package com.polito.mad.bikeponyapp.persistence;

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public abstract class  AbstractDAO<T,E extends SQLiteOpenHelper> implements DAO<T> {
	
	
	private SQLiteDatabase db;
	private E helper; 
	
	public  AbstractDAO(E helper)
	{
		this.helper=helper;
	}
	
	public void open()
	{
		if(db ==null || !db.isOpen())
			db = helper.getWritableDatabase();
	}
	
	public void close()
	{
		if(db!=null)
			db.close();
		
		helper.close();
		db=null;
	}
	
	public SQLiteDatabase getDb() {
		open();
		return db;
	}

	public E getHelper() {
		return helper;
	}

	protected abstract String[] getColumnNames();
	protected abstract String getDbName();
}
